﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using DTO;
namespace DAO
{
    public class NhanVienDAO
    {
        #region SelectNhanVienByMaNV
        public static NhanVienDTO SelectNhanVienByMaNV(String manv)
        {
            NhanVienDTO nv = new NhanVienDTO();
            try
            {
                
                List<SqlParameter> sqlParams = new List<SqlParameter>();//jkh
                sqlParams.Add(new SqlParameter("@manv", manv));//kjhj
                DataTable dt = DataProvider.ExecuteQuery("sp_SelectNhanVienByMaNV", sqlParams);
                DataRow dr = dt.Rows[0];
                nv.MANV = dr["MANV"].ToString();
                nv.TEN = dr["TEN"].ToString();
                nv.NGAYSINH = DateTime.Parse(dr["NGAYSINH"].ToString());
                nv.DCHI = dr["DCHI"].ToString();
                nv.LOAINV = dr["LOAINV"].ToString();
                nv.GTINH = bool.Parse(dr["GTINH"].ToString());
                nv.MKHAU = dr["MKHAU"].ToString();
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return nv;
        }
        #endregion

        #region SelectALLNhanVien
        public static List<NhanVienDTO> SelectALLNhanVien()
        {

            List<NhanVienDTO> list = new List<NhanVienDTO>();
            try
            {
                DataTable dt = DataProvider.ExecuteQuery("sp_SelectALLNhanVien");
                foreach (DataRow dr in dt.Rows)
                {
                    NhanVienDTO nv = new NhanVienDTO();
                    nv.MANV = dr["MANV"].ToString();
                    nv.TEN = dr["TEN"].ToString();
                    nv.NGAYSINH = DateTime.Parse(dr["NGAYSINH"].ToString());
                    nv.DCHI = dr["DCHI"].ToString();
                    nv.LOAINV = dr["LOAINV"].ToString();
                    nv.GTINH = bool.Parse(dr["GTINH"].ToString());
                    nv.MKHAU = dr["MKHAU"].ToString();                   
                    list.Add(nv);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return list;
        }
        #endregion

        #region SelectNhanVienByMaNVPASS
        public static int SelectNhanVienByMaNVPASS(String manv, String pw)
        {
            int kt = 0;
            try
            {
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@manv", manv));
                sqlParams.Add(new SqlParameter("@pass", pw));               
                DataTable dt = DataProvider.ExecuteQuery("sp_SelectNhanVienByMaNVPASS", sqlParams);
                kt = dt.Rows.Count;
                if (kt > 0)
                {
                    kt = 1;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return kt;
        }
        #endregion
    }
}
